package com.hc.controller;

import com.hc.util.ThreadManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author fengq
 */
@RestController
@RequestMapping("/api/thread")
public class ThreadController {

    @Autowired
    private ThreadManager threadManager;

    /**
     * 接口 1：添加线程并阻塞
     *
     * @param id 线程标识
     */
    @GetMapping("/block")
    public String blockThread(String id) {
        threadManager.addAndBlock(id);
        return "Thread blocked for id: " + id;
    }

    /**
     * 接口 2：唤醒线程
     *
     * @param id 线程标识
     */
    @GetMapping("/notify")
    public String notifyThread(String id) {
        threadManager.notifyThread(id);
        return "Thread notified for id: " + id;
    }
}